package com.qupai.controller.admin;


import com.qupai.dto.AuctioneerAddDTO;
import com.qupai.dto.AuctioneerPageQueryDTO;
import com.qupai.entity.Auctioneer;
import com.qupai.result.PageResult;
import com.qupai.result.Result;
import com.qupai.service.IAuctioneerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 拍卖师表，存储拍卖师信息 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-07-30
 */
@RestController("adminAuctioneerController")
@RequestMapping("/admin/auctioneer")
@Slf4j
@Tag(name = "志愿-拍卖师相关接口")
public class AuctioneerController {

    @Resource
    private IAuctioneerService auctioneerService;

    /**
     * 新增拍卖师
     */
    @PostMapping()
    @Operation(summary = "新增拍卖师")
    public Result<String> add(@RequestBody AuctioneerAddDTO auctioneerAddDTO){
        log.info("新增拍卖师：{}",auctioneerAddDTO);
        auctioneerService.add(auctioneerAddDTO);
        return Result.success();
    }

    @PostMapping("/addChange/{auctioneerId}")
    @Operation(summary = "给指定id的拍卖师新增一次举办拍卖会的机会")
    public Result<String> addChange(@PathVariable Long auctioneerId){
        auctioneerService.addChange(auctioneerId);
        return Result.success();
    }

    /**
     * 拍卖师分页查询
     */
    @GetMapping("/page")
    @Operation(summary = "拍卖师分页查询")
    public Result<PageResult>page(@ParameterObject AuctioneerPageQueryDTO auctioneerPageQueryDTO){
        log.info("拍卖师分页查询,参数为：{}",auctioneerPageQueryDTO);
        PageResult pageResult= auctioneerService.pageQuery(auctioneerPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 启用/禁用拍卖师账号
     */
    @PostMapping("/status/{status}")
    @Operation(summary = "启用/禁用拍卖师账号")
    public Result<String> startOrStop(@PathVariable Integer status, Long id){
        log.info("启用/禁用拍卖师账号,status:{},id:{}",status,id);
        auctioneerService.startOrStop(status,id);
        return Result.success();
    }

    /**
     * 根据id查询拍卖师
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询拍卖师")
    public Result<Auctioneer> getById(@PathVariable Long id){
        Auctioneer auctioneer=auctioneerService.getById(id);
        return Result.success(auctioneer);
    }

    /**
     * 编辑拍卖师信息
     */
    @PutMapping
    @Operation(summary = "编辑拍卖师信息")
    public Result<String> update(@RequestBody Auctioneer auctioneer){
        log.info("编辑拍卖师信息,参数为：{}",auctioneer);
        auctioneerService.updateById(auctioneer);
        return Result.success();
    }


}
